package com.atguigu.dwm.model.controller;

import com.atguigu.dwm.common.bean.QueryInfo;
import com.atguigu.dwm.common.bean.Result;
import com.atguigu.dwm.model.bean.DmDimension;
import com.atguigu.dwm.model.bean.DmTable;
import com.atguigu.dwm.model.bean.DmTableColumn;
import com.atguigu.dwm.model.service.DmTableColumnService;
import com.atguigu.dwm.model.service.DmTableService;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 数据表 前端控制器
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/data-model/table")
public class DmTableController {

    @Autowired
    DmTableService dmTableService;

    @Autowired
    DmTableColumnService dmTableColumnService;

    @PostMapping("/detail")
    public Result save(@RequestBody DmTable dmTable) {

        dmTableService.saveTableAll(dmTable);
        return Result.ok(dmTable);
    }


    @GetMapping("list")
    public Result getList(QueryInfo queryInfo){  //

        List<DmTable> list = dmTableService.getQueryList(queryInfo);
        Integer total = dmTableService.getQueryTotal(queryInfo);
        return Result.ok(list,total);

    }

    @GetMapping("/detail/{id}")
    public Result getDetail(@PathVariable("id") Long id){
        DmTable dmTable=  dmTableService.getTableAll(id);

        return Result.ok(dmTable);
    }

    @PostMapping("/hive/{tableId}")
    public  Result  submitToHive(@PathVariable("tableId") Long tableId){
        try {
            dmTableService.submitToHive(tableId);
        } catch ( Exception e) {
            e.printStackTrace();
            return  Result.error("提交 hive 失败 ");
        }
        return  Result.ok();
    }


}
